columntransformer in randomizedsearchcv

80

import seaborn as sns
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import OneHotEncoder, KBinsDiscretizer, MinMaxScaler
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression

df = sns.load_dataset('titanic')[['survived', 'age', 'embarked']]
X_train, X_test, y_train, y_test = train_test_split(df.drop(columns='survived'), df['survived'], test_size=0.2, 
                                                    random_state=123)
num = ['age']
cat = ['embarked']

num_transformer = Pipeline(steps=[('imputer', SimpleImputer()), 
                                  ('discritiser', KBinsDiscretizer(encode='ordinal', strategy='uniform')),
                                  ('scaler', MinMaxScaler())])

cat_transformer = Pipeline(steps=[('imputer', SimpleImputer(strategy='constant', fill_value='missing')),
                                  ('onehot', OneHotEncoder(handle_unknown='ignore'))])

preprocessor = ColumnTransformer(transformers=[('num', num_transformer, num),
                                               ('cat', cat_transformer, cat)])

pipe = Pipeline(steps=[('preprocessor', preprocessor),
                       ('classiffier', LogisticRegression(random_state=1, max_iter=10000))])

param_grid = {'preprocessor__num__imputer__strategy' : ['mean', 'median'],
              'preprocessor__num__discritiser__n_bins' : range(5,10),
              'classiffier__C' : [0.1, 10, 100],
              'classiffier__solver' : ['liblinear', 'saga']}
grid_search = GridSearchCV(pipe, param_grid=param_grid, cv=10)
grid_search.fit(X_train, y_train)

Comments

Submit
0 Comments

More Questions

boolean in crandom number c ModuleNotFoundError: No module named cv2
check dns server in linuxread files in c how to get user input in c
print boolean value in clatex font sizes see if two strings are equal in C
how to download file in powershellprintf with bool invoke-webrequest download file
write in file in cmongodb delete all documents how to genrate a random number in C
how to print boolean in csleep in c programming install zoom on ubuntu
c concatenate stringstake array as input in c install gitk mac
remove element from np arrayprint an array in c C static libraries (creating object files)
exponentials in cC++ initalize int16_t value script hack blox fruti
pointer operatorcheck command line input is a number in c what is covert channel
sqlserver insert with set identity-usr-bin-env: python-r: No such file or directory linear search program in c
Uri-beecrowd problem no - 1099 solution in Cc addition The fscanf and fprintf functions
function that reverses the content of an array of integers.how to search in a file in c Couldnt create temporary file to work with
WARNING: QA Issue: bgslibrary-dev rdepends on libopencv-imgproc, but it isnt a build dependency, missing opencv in DEPENDS or PACKAGECONFIG [build-deps]reading arrays from stdin c add a item to cart woocomerce with quantity
Using PostgreSQL array to store many-to-many relationship using sqlalchemylistas enlazadas- linked lists binary sorting
c how to include variables of other c filec strcat uri-beecrowd problem no - 1133 solution in C